home *** CD-ROM | disk | FTP | other *** search
/ Aminet 40 / Aminet 40 (2000)(Schatztruhe)[!][Dec 2000].iso / Aminet / dev / lang / Python16_Src.lha / Python16_Source / Modules / regexmodule.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-10  |  15.1 KB  |  719 lines

  1. /*
  2. XXX support range parameter on search
  3. XXX support mstop parameter on search
  4. */
  5.  
  6. /* Regular expression objects */
  7. /* This uses Tatu Ylonen's copyleft-free reimplementation of
  8.    GNU regular expressions */
  9.  
  10. #include "Python.h"
  11.  
  12. #include <ctype.h>
  13.  
  14. #include "regexpr.h"
  15.  
  16. static PyObject *RegexError;    /* Exception */    
  17.  
  18. typedef struct {
  19.     PyObject_HEAD
  20.     struct re_pattern_buffer re_patbuf; /* The compiled expression */
  21.     struct re_registers re_regs; /* The registers from the last match */
  22.     char re_fastmap[256];    /* Storage for fastmap */
  23.     PyObject *re_translate;    /* String object for translate table */
  24.     PyObject *re_lastok;    /* String object last matched/searched */
  25.     PyObject *re_groupindex;    /* Group name to index dictionary */
  26.     PyObject *re_givenpat;    /* Pattern with symbolic groups */
  27.     PyObject *re_realpat;    /* Pattern without symbolic groups */
  28. } regexobject;
  29.  
  30. #include "protos/regexmodule.h"
  31.  
  32. /* Regex object methods */
  33.  
  34. static void
  35. reg_dealloc(re)
  36.     regexobject *re;
  37. {
  38.     if (re->re_patbuf.buffer)
  39.         PyMem_DEL(re->re_patbuf.buffer);
  40.     Py_XDECREF(re->re_translate);
  41.     Py_XDECREF(re->re_lastok);
  42.     Py_XDECREF(re->re_groupindex);
  43.     Py_XDECREF(re->re_givenpat);
  44.     Py_XDECREF(re->re_realpat);
  45.     PyObject_Del(re);
  46. }
  47.  
  48. static PyObject *
  49. makeresult(regs)
  50.     struct re_registers *regs;
  51. {
  52.     PyObject *v;
  53.     int i;
  54.     static PyObject *filler = NULL;
  55.  
  56.     if (filler == NULL) {
  57.         filler = Py_BuildValue("(ii)", -1, -1);
  58.         if (filler == NULL)
  59.             return NULL;
  60.     }
  61.     v = PyTuple_New(RE_NREGS);
  62.     if (v == NULL)
  63.         return NULL;
  64.  
  65.     for (i = 0; i < RE_NREGS; i++) {
  66.         int lo = regs->start[i];
  67.         int hi = regs->end[i];
  68.         PyObject *w;
  69.         if (lo == -1 && hi == -1) {
  70.             w = filler;
  71.             Py_INCREF(w);
  72.         }
  73.         else
  74.             w = Py_BuildValue("(ii)", lo, hi);
  75.         if (w == NULL || PyTuple_SetItem(v, i, w) < 0) {
  76.             Py_DECREF(v);
  77.             return NULL;
  78.         }
  79.     }
  80.     return v;
  81. }
  82.  
  83. static PyObject *
  84. regobj_match(re, args)
  85.     regexobject *re;
  86.     PyObject *args;
  87. {
  88.     PyObject *argstring;
  89.     char *buffer;
  90.     int size;
  91.     int offset = 0;
  92.     int result;
  93.  
  94.     if (!PyArg_ParseTuple(args, "O|i:match", &argstring, &offset))
  95.         return NULL;
  96.     if (!PyArg_Parse(argstring, "t#", &buffer, &size))
  97.         return NULL;
  98.  
  99.     if (offset < 0 || offset > size) {
  100.         PyErr_SetString(RegexError, "match offset out of range");
  101.         return NULL;
  102.     }
  103.     Py_XDECREF(re->re_lastok);
  104.     re->re_lastok = NULL;
  105.     result = _Py_re_match(&re->re_patbuf, (unsigned char *)buffer, size, offset,
  106.                   &re->re_regs);
  107.     if (result < -1) {
  108.         /* Serious failure of some sort; if re_match didn't 
  109.            set an exception, raise a generic error */
  110.             if (!PyErr_Occurred())
  111.                 PyErr_SetString(RegexError, "match failure");
  112.         return NULL;
  113.     }
  114.     if (result >= 0) {
  115.         Py_INCREF(argstring);
  116.         re->re_lastok = argstring;
  117.     }
  118.     return PyInt_FromLong((long)result); /* Length of the match or -1 */
  119. }
  120.  
  121. static PyObject *
  122. regobj_search(re, args)
  123.     regexobject *re;
  124.     PyObject *args;
  125. {
  126.     PyObject *argstring;
  127.     char *buffer;
  128.     int size;
  129.     int offset = 0;
  130.     int range;
  131.     int result;
  132.     
  133.     if (!PyArg_ParseTuple(args, "O|i:search", &argstring, &offset))
  134.         return NULL;
  135.     if (!PyArg_Parse(argstring, "t#:search", &buffer, &size))
  136.         return NULL;
  137.  
  138.     if (offset < 0 || offset > size) {
  139.         PyErr_SetString(RegexError, "search offset out of range");
  140.         return NULL;
  141.     }
  142.     /* NB: In Emacs 18.57, the documentation for re_search[_2] and
  143.        the implementation don't match: the documentation states that
  144.        |range| positions are tried, while the code tries |range|+1
  145.        positions.  It seems more productive to believe the code! */
  146.     range = size - offset;
  147.     Py_XDECREF(re->re_lastok);
  148.     re->re_lastok = NULL;
  149.     result = _Py_re_search(&re->re_patbuf, (unsigned char *)buffer, size, offset, range,
  150.                &re->re_regs);
  151.     if (result < -1) {
  152.         /* Serious failure of some sort; if re_match didn't 
  153.            set an exception, raise a generic error */
  154.             if (!PyErr_Occurred())
  155.                   PyErr_SetString(RegexError, "match failure");
  156.         return NULL;
  157.     }
  158.     if (result >= 0) {
  159.         Py_INCREF(argstring);
  160.         re->re_lastok = argstring;
  161.     }
  162.     return PyInt_FromLong((long)result); /* Position of the match or -1 */
  163. }
  164.  
  165. /* get the group from the regex where index can be a string (group name) or
  166.    an integer index [0 .. 99]
  167.  */
  168. static PyObject*
  169. group_from_index(re, index)
  170.     regexobject *re;
  171.     PyObject *index;
  172. {
  173.     int i, a, b;
  174.     char *v;
  175.  
  176.     if (PyString_Check(index))
  177.         if (re->re_groupindex == NULL ||
  178.             !(index = PyDict_GetItem(re->re_groupindex, index)))
  179.         {
  180.             PyErr_SetString(RegexError,
  181.                     "group() group name doesn't exist");
  182.             return NULL;
  183.         }
  184.  
  185.     i = PyInt_AsLong(index);
  186.     if (i == -1 && PyErr_Occurred())
  187.         return NULL;
  188.  
  189.     if (i < 0 || i >= RE_NREGS) {
  190.         PyErr_SetString(RegexError, "group() index out of range");
  191.         return NULL;
  192.     }
  193.     if (re->re_lastok == NULL) {
  194.         PyErr_SetString(RegexError,
  195.                "group() only valid after successful match/search");
  196.         return NULL;
  197.     }
  198.     a = re->re_regs.start[i];
  199.     b = re->re_regs.end[i];
  200.     if (a < 0 || b < 0) {
  201.         Py_INCREF(Py_None);
  202.         return Py_None;
  203.     }
  204.     
  205.     if (!(v = PyString_AsString(re->re_lastok)))
  206.         return NULL;
  207.  
  208.     return PyString_FromStringAndSize(v+a, b-a);
  209. }
  210.  
  211.  
  212. static PyObject *
  213. regobj_group(re, args)
  214.     regexobject *re;
  215.     PyObject *args;
  216. {
  217.     int n = PyTuple_Size(args);
  218.     int i;
  219.     PyObject *res = NULL;
  220.  
  221.     if (n < 0)
  222.         return NULL;
  223.     if (n == 0) {
  224.         PyErr_SetString(PyExc_TypeError, "not enough arguments");
  225.         return NULL;
  226.     }
  227.     if (n == 1) {
  228.         /* return value is a single string */
  229.         PyObject *index = PyTuple_GetItem(args, 0);
  230.         if (!index)
  231.             return NULL;
  232.         
  233.         return group_from_index(re, index);
  234.     }
  235.  
  236.     /* return value is a tuple */
  237.     if (!(res = PyTuple_New(n)))
  238.         return NULL;
  239.  
  240.     for (i = 0; i < n; i++) {
  241.         PyObject *index = PyTuple_GetItem(args, i);
  242.         PyObject *group = NULL;
  243.  
  244.         if (!index)
  245.             goto finally;
  246.         if (!(group = group_from_index(re, index)))
  247.             goto finally;
  248.         if (PyTuple_SetItem(res, i, group) < 0)
  249.             goto finally;
  250.     }
  251.     return res;
  252.  
  253.   finally:
  254.     Py_DECREF(res);
  255.     return NULL;
  256. }
  257.  
  258.  
  259. static struct PyMethodDef reg_methods[] = {
  260.     {"match",    (PyCFunction)regobj_match, 1},
  261.     {"search",    (PyCFunction)regobj_search, 1},
  262.     {"group",    (PyCFunction)regobj_group, 1},
  263.     {NULL,        NULL}        /* sentinel */
  264. };
  265.  
  266.  
  267.  
  268. static char* members[] = {
  269.     "last", "regs", "translate",
  270.     "groupindex", "realpat", "givenpat",
  271.     NULL
  272. };
  273.  
  274.  
  275. static PyObject *
  276. regobj_getattr(re, name)
  277.     regexobject *re;
  278.     char *name;
  279. {
  280.     if (strcmp(name, "regs") == 0) {
  281.         if (re->re_lastok == NULL) {
  282.             Py_INCREF(Py_None);
  283.             return Py_None;
  284.         }
  285.         return makeresult(&re->re_regs);
  286.     }
  287.     if (strcmp(name, "last") == 0) {
  288.         if (re->re_lastok == NULL) {
  289.             Py_INCREF(Py_None);
  290.             return Py_None;
  291.         }
  292.         Py_INCREF(re->re_lastok);
  293.         return re->re_lastok;
  294.     }
  295.     if (strcmp(name, "translate") == 0) {
  296.         if (re->re_translate == NULL) {
  297.             Py_INCREF(Py_None);
  298.             return Py_None;
  299.         }
  300.         Py_INCREF(re->re_translate);
  301.         return re->re_translate;
  302.     }
  303.     if (strcmp(name, "groupindex") == 0) {
  304.         if (re->re_groupindex == NULL) {
  305.             Py_INCREF(Py_None);
  306.             return Py_None;
  307.         }
  308.         Py_INCREF(re->re_groupindex);
  309.         return re->re_groupindex;
  310.     }
  311.     if (strcmp(name, "realpat") == 0) {
  312.         if (re->re_realpat == NULL) {
  313.             Py_INCREF(Py_None);
  314.             return Py_None;
  315.         }
  316.         Py_INCREF(re->re_realpat);
  317.         return re->re_realpat;
  318.     }
  319.     if (strcmp(name, "givenpat") == 0) {
  320.         if (re->re_givenpat == NULL) {
  321.             Py_INCREF(Py_None);
  322.             return Py_None;
  323.         }
  324.         Py_INCREF(re->re_givenpat);
  325.         return re->re_givenpat;
  326.     }
  327.     if (strcmp(name, "__members__") == 0) {
  328.         int i = 0;
  329.         PyObject *list = NULL;
  330.  
  331.         /* okay, so it's unlikely this list will change that often.
  332.            still, it's easier to change it in just one place.
  333.          */
  334.         while (members[i])
  335.             i++;
  336.         if (!(list = PyList_New(i)))
  337.             return NULL;
  338.  
  339.         i = 0;
  340.         while (members[i]) {
  341.             PyObject* v = PyString_FromString(members[i]);
  342.             if (!v || PyList_SetItem(list, i, v) < 0) {
  343.                 Py_DECREF(list);
  344.                 return NULL;
  345.             }
  346.             i++;
  347.         }
  348.         return list;
  349.     }
  350.     return Py_FindMethod(reg_methods, (PyObject *)re, name);
  351. }
  352.  
  353. static PyTypeObject Regextype = {
  354.     PyObject_HEAD_INIT(&PyType_Type)
  355.     0,                     /*ob_size*/
  356.     "regex",                 /*tp_name*/
  357.     sizeof(regexobject),             /*tp_size*/
  358.     0,                     /*tp_itemsize*/
  359.     /* methods */
  360.     (destructor)reg_dealloc,         /*tp_dealloc*/
  361.     0,                     /*tp_print*/
  362.     (getattrfunc)regobj_getattr,         /*tp_getattr*/
  363.     0,                     /*tp_setattr*/
  364.     0,                     /*tp_compare*/
  365.     0,                     /*tp_repr*/
  366. };
  367.  
  368. /* reference counting invariants:
  369.    pattern: borrowed
  370.    translate: borrowed
  371.    givenpat: borrowed
  372.    groupindex: transferred
  373. */
  374. static PyObject *
  375. newregexobject(pattern, translate, givenpat, groupindex)
  376.     PyObject *pattern;
  377.     PyObject *translate;
  378.     PyObject *givenpat;
  379.     PyObject *groupindex;
  380. {
  381.     regexobject *re;
  382.     char *pat;
  383.     int size;
  384.  
  385.     if (!PyArg_Parse(pattern, "t#", &pat, &size))
  386.         return NULL;
  387.     
  388.     if (translate != NULL && PyString_Size(translate) != 256) {
  389.         PyErr_SetString(RegexError,
  390.                 "translation table must be 256 bytes");
  391.         return NULL;
  392.     }
  393.     re = PyObject_New(regexobject, &Regextype);
  394.     if (re != NULL) {
  395.         char *error;
  396.         re->re_patbuf.buffer = NULL;
  397.         re->re_patbuf.allocated = 0;
  398.         re->re_patbuf.fastmap = (unsigned char *)re->re_fastmap;
  399.         if (translate) {
  400.             re->re_patbuf.translate = (unsigned char *)PyString_AsString(translate);
  401.             if (!re->re_patbuf.translate)
  402.                 goto finally;
  403.             Py_INCREF(translate);
  404.         }
  405.         else
  406.             re->re_patbuf.translate = NULL;
  407.         re->re_translate = translate;
  408.         re->re_lastok = NULL;
  409.         re->re_groupindex = groupindex;
  410.         Py_INCREF(pattern);
  411.         re->re_realpat = pattern;
  412.         Py_INCREF(givenpat);
  413.         re->re_givenpat = givenpat;
  414.         error = _Py_re_compile_pattern((unsigned char *)pat, size, &re->re_patbuf);
  415.         if (error != NULL) {
  416.             PyErr_SetString(RegexError, error);
  417.             goto finally;
  418.         }
  419.     }
  420.     return (PyObject *)re;
  421.   finally:
  422.     Py_DECREF(re);
  423.     return NULL;
  424. }
  425.  
  426. static PyObject *
  427. regex_compile(self, args)
  428.     PyObject *self;
  429.     PyObject *args;
  430. {
  431.     PyObject *pat = NULL;
  432.     PyObject *tran = NULL;
  433.  
  434.     if (!PyArg_ParseTuple(args, "S|S:compile", &pat, &tran))
  435.         return NULL;
  436.     return newregexobject(pat, tran, pat, NULL);
  437. }
  438.  
  439. static PyObject *
  440. symcomp(pattern, gdict)
  441.     PyObject *pattern;
  442.     PyObject *gdict;
  443. {
  444.     char *opat, *oend, *o, *n, *g, *v;
  445.     int group_count = 0;
  446.     int sz;
  447.     int escaped = 0;
  448.     char name_buf[128];
  449.     PyObject *npattern;
  450.     int require_escape = re_syntax & RE_NO_BK_PARENS ? 0 : 1;
  451.  
  452.     if (!(opat = PyString_AsString(pattern)))
  453.         return NULL;
  454.  
  455.     if ((sz = PyString_Size(pattern)) < 0)
  456.         return NULL;
  457.  
  458.     oend = opat + sz;
  459.     o = opat;
  460.  
  461.     if (oend == opat) {
  462.         Py_INCREF(pattern);
  463.         return pattern;
  464.     }
  465.  
  466.     if (!(npattern = PyString_FromStringAndSize((char*)NULL, sz)) ||
  467.         !(n = PyString_AsString(npattern)))
  468.         return NULL;
  469.  
  470.     while (o < oend) {
  471.         if (*o == '(' && escaped == require_escape) {
  472.             char *backtrack;
  473.             escaped = 0;
  474.             ++group_count;
  475.             *n++ = *o;
  476.             if (++o >= oend || *o != '<')
  477.                 continue;
  478.             /* *o == '<' */
  479.             if (o+1 < oend && *(o+1) == '>')
  480.                 continue;
  481.             backtrack = o;
  482.             g = name_buf;
  483.             for (++o; o < oend;) {
  484.                 if (*o == '>') {
  485.                     PyObject *group_name = NULL;
  486.                     PyObject *group_index = NULL;
  487.                     *g++ = '\0';
  488.                     group_name = PyString_FromString(name_buf);
  489.                     group_index = PyInt_FromLong(group_count);
  490.                     if (group_name == NULL ||
  491.                     group_index == NULL ||
  492.                     PyDict_SetItem(gdict, group_name,
  493.                                group_index) != 0)
  494.                     {
  495.                         Py_XDECREF(group_name);
  496.                         Py_XDECREF(group_index);
  497.                         Py_XDECREF(npattern);
  498.                         return NULL;
  499.                     }
  500.                     Py_DECREF(group_name);
  501.                     Py_DECREF(group_index);
  502.                     ++o;     /* eat the '>' */
  503.                     break;
  504.                 }
  505.                 if (!isalnum(Py_CHARMASK(*o)) && *o != '_') {
  506.                     o = backtrack;
  507.                     break;
  508.                 }
  509.                 *g++ = *o++;
  510.             }
  511.         }
  512.         else if (*o == '[' && !escaped) {
  513.             *n++ = *o;
  514.             ++o;             /* eat the char following '[' */
  515.             *n++ = *o;
  516.             while (o < oend && *o != ']') {
  517.                 ++o;
  518.                 *n++ = *o;
  519.             }
  520.             if (o < oend)
  521.                 ++o;
  522.         }
  523.         else if (*o == '\\') {
  524.             escaped = 1;
  525.             *n++ = *o;
  526.             ++o;
  527.         }
  528.         else {
  529.             escaped = 0;
  530.             *n++ = *o;
  531.             ++o;
  532.         }
  533.     }
  534.  
  535.     if (!(v = PyString_AsString(npattern))) {
  536.         Py_DECREF(npattern);
  537.         return NULL;
  538.     }
  539.     /* _PyString_Resize() decrements npattern on failure */
  540.     if (_PyString_Resize(&npattern, n - v) == 0)
  541.         return npattern;
  542.     else {
  543.         return NULL;
  544.     }
  545.  
  546. }
  547.  
  548. static PyObject *
  549. regex_symcomp(self, args)
  550.     PyObject *self;
  551.     PyObject *args;
  552. {
  553.     PyObject *pattern;
  554.     PyObject *tran = NULL;
  555.     PyObject *gdict = NULL;
  556.     PyObject *npattern;
  557.     PyObject *retval = NULL;
  558.  
  559.     if (!PyArg_ParseTuple(args, "S|S:symcomp", &pattern, &tran))
  560.         return NULL;
  561.  
  562.     gdict = PyDict_New();
  563.     if (gdict == NULL || (npattern = symcomp(pattern, gdict)) == NULL) {
  564.         Py_DECREF(gdict);
  565.         Py_DECREF(pattern);
  566.         return NULL;
  567.     }
  568.     retval = newregexobject(npattern, tran, pattern, gdict);
  569.     Py_DECREF(npattern);
  570.     return retval;
  571. }
  572.  
  573.  
  574. static PyObject *cache_pat;
  575. static PyObject *cache_prog;
  576.  
  577. static int
  578. update_cache(pat)
  579.     PyObject *pat;
  580. {
  581.     PyObject *tuple = Py_BuildValue("(O)", pat);
  582.     int status = 0;
  583.  
  584.     if (!tuple)
  585.         return -1;
  586.  
  587.     if (pat != cache_pat) {
  588.         Py_XDECREF(cache_pat);
  589.         cache_pat = NULL;
  590.         Py_XDECREF(cache_prog);
  591.         cache_prog = regex_compile((PyObject *)NULL, tuple);
  592.         if (cache_prog == NULL) {
  593.             status = -1;
  594.             goto finally;
  595.         }
  596.         cache_pat = pat;
  597.         Py_INCREF(cache_pat);
  598.     }
  599.   finally:
  600.     Py_DECREF(tuple);
  601.     return status;
  602. }
  603.  
  604. static PyObject *
  605. regex_match(self, args)
  606.     PyObject *self;
  607.     PyObject *args;
  608. {
  609.     PyObject *pat, *string;
  610.     PyObject *tuple, *v;
  611.  
  612.     if (!PyArg_Parse(args, "(SS)", &pat, &string))
  613.         return NULL;
  614.     if (update_cache(pat) < 0)
  615.         return NULL;
  616.  
  617.     if (!(tuple = Py_BuildValue("(S)", string)))
  618.         return NULL;
  619.     v = regobj_match((regexobject *)cache_prog, tuple);
  620.     Py_DECREF(tuple);
  621.     return v;
  622. }
  623.  
  624. static PyObject *
  625. regex_search(self, args)
  626.     PyObject *self;
  627.     PyObject *args;
  628. {
  629.     PyObject *pat, *string;
  630.     PyObject *tuple, *v;
  631.  
  632.     if (!PyArg_Parse(args, "(SS)", &pat, &string))
  633.         return NULL;
  634.     if (update_cache(pat) < 0)
  635.         return NULL;
  636.  
  637.     if (!(tuple = Py_BuildValue("(S)", string)))
  638.         return NULL;
  639.     v = regobj_search((regexobject *)cache_prog, tuple);
  640.     Py_DECREF(tuple);
  641.     return v;
  642. }
  643.  
  644. static PyObject *
  645. regex_set_syntax(self, args)
  646.     PyObject *self;
  647.     PyObject *args;
  648. {
  649.     int syntax;
  650.     if (!PyArg_Parse(args, "i", &syntax))
  651.         return NULL;
  652.     syntax = re_set_syntax(syntax);
  653.     /* wipe the global pattern cache */
  654.     Py_XDECREF(cache_pat);
  655.     cache_pat = NULL;
  656.     Py_XDECREF(cache_prog);
  657.     cache_prog = NULL;
  658.     return PyInt_FromLong((long)syntax);
  659. }
  660.  
  661. static PyObject *
  662. regex_get_syntax(self, args)
  663.     PyObject *self;
  664.     PyObject *args;
  665. {
  666.     if (!PyArg_Parse(args, ""))
  667.         return NULL;
  668.     return PyInt_FromLong((long)re_syntax);
  669. }
  670.  
  671.  
  672. static struct PyMethodDef regex_global_methods[] = {
  673.     {"compile",    regex_compile, 1},
  674.     {"symcomp",    regex_symcomp, 1},
  675.     {"match",    regex_match, 0},
  676.     {"search",    regex_search, 0},
  677.     {"set_syntax",    regex_set_syntax, 0},
  678.     {"get_syntax",  regex_get_syntax, 0},
  679.     {NULL,        NULL}             /* sentinel */
  680. };
  681.  
  682. DL_EXPORT(void)
  683. initregex()
  684. {
  685.     PyObject *m, *d, *v;
  686.     int i;
  687.     char *s;
  688.     
  689.     m = Py_InitModule("regex", regex_global_methods);
  690.     d = PyModule_GetDict(m);
  691.     
  692.     /* Initialize regex.error exception */
  693.     v = RegexError = PyErr_NewException("regex.error", NULL, NULL);
  694.     if (v == NULL || PyDict_SetItemString(d, "error", v) != 0)
  695.         goto finally;
  696.     
  697.     /* Initialize regex.casefold constant */
  698.     if (!(v = PyString_FromStringAndSize((char *)NULL, 256)))
  699.         goto finally;
  700.     
  701.     if (!(s = PyString_AsString(v)))
  702.         goto finally;
  703.  
  704.     for (i = 0; i < 256; i++) {
  705.         if (isupper(i))
  706.             s[i] = tolower(i);
  707.         else
  708.             s[i] = i;
  709.     }
  710.     if (PyDict_SetItemString(d, "casefold", v) < 0)
  711.         goto finally;
  712.     Py_DECREF(v);
  713.  
  714.     if (!PyErr_Occurred())
  715.         return;
  716.   finally:
  717.     /* Nothing */ ;
  718. }
  719.